package com.situ.stmall.manger.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

//封装服务器向客户端返回的数据
@Data   //相当于@Getter 两个注解
@ToString
@NoArgsConstructor
public class Result {
    //操作的状态码
    private Integer code;
    //返回错误的信息
    private String msg;
    //任何类型的数据，返回查询的结果
    private Object data;

    public static Result success(Integer code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result success(Object data) {
        return success(0, null, data);
    }

    public static Result success() {
        return success(0, null, null);
    }

    public static Result error(Integer code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result error(Integer code,String msg) {
        return error(code,msg,null);
    }

    public static Result error(String msg) {
        return error(-1, msg, null);
    }
}
